/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var sel = $.Params.create();
    sel.addParams("page",0);
    sel.addParams("rows",rows);

    getData("",0);

    //判断checkbox状态
    $("#selAll").on("click",function () {
        var check = $(this).attr("checked");
        if(check == undefined || check == "undefined"){
            $("input[type=checkbox]").attr("checked","checked");
        }else{
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //删除事件
    $('#delBtn').on("click",function(){
        var pararms = getCheckData();
        delData(pararms);
    });

    //查询
    $("#searchBtn").on("click",function () {
        var selTitle = $("#searchVal").val();
        var selClassify = $("#selClassify").val();
        
        if(selTitle == undefined || selTitle == "undefined"){
            alert("查询的内容不能为undefined！");
        }else{
            getData(selTitle,selClassify);
        }
    })


    //获取数据
    function getData(title,type){
        getPageData(sel,getIP()+"comment/getCommentAndLog?title="+title+"&type="+type,function(data){
            if(data.success){
                var html = "";
                $.each(data.result, function(i,val) {
                    html+="<tr role='row'' class='even'><td>"+parseInt(i+1)+"</td><td class='sorting_1'>"+decodeURI(val.TITLE)+
                        "</td><td><a href='"+getIP()+"commentManage/commentLog_info.html?courseId="+val.id+"'>"+val.pinglun+"</a></td>"+
                        "<td>"+val.dianji+"</td>"
                        if(val.type==1001){
                            html+= "<td>大课堂</td>";
                        }else if(val.type==1002){
                            html+= "<td>分享汇</td>";
                        }else if(val.type==1003){
                            html+="<td>新闻</td>";
                        }
                    html+="</tr>";

                });
                $("#listContainer").html(html);
            }
        })
    }

    //删除数据
    function delData(ids){
        var del = $.Params.create();
        del.addParams("params",ids)
        del.ajax(getIP()+"comment/deleteComment",function(data){
            if(data.success){
                alert("删除成功！");
                getData("",0);
            }
        })
    }
});
